// JavaScript Document
var _ = $.o;
oAdmin =
{
	"openFoot":function(url,p)
	{
		p = p?p:'50%';
		this.sysBar('*,'+p);
		window.parent.foot.document.location.replace(url);
	},
	"sysBar":function(v)
	{
		if(window.parent.main_foot.rows=='*,0')
		{
			window.parent.main_foot.rows=v;
		}else if(v == '*,0')
		{
			window.parent.main_foot.rows='*,0';
		}
	},
	"closeFoot":function()
	{
		try
		{
			if(window.parent.main_foot.rows!='*,0')
			{
				this.sysBar('*,0');
				window.parent.foot.document.location.replace('about:blank');
			}
		}catch(e){}
	},
	"get":function(url)
	{
	   fJson.get(url);    
	},
	"footGoWin":function(a)
	{
		a	=a?a:'about:blank';
		window.parent.data.document.location.replace(a);
	},
	"msgYn":function (msg)
	{
		msg = msg ? msg : '提示:刪除將無法恢復!你確認要刪除嗎?';
		if(window.confirm(msg))
		{
			return true;
		}else
		{
			return false;	
		}
	},
	"menu":function()
	{
	    try
		{
			if(window.parent.left_main.cols=='0,*')
			{
				window.parent.left_main.cols='200,*';
			}else
			{
				window.parent.left_main.cols='0,*';
			}
		}catch(e){};
	}
};

var oFrom  	=
{
	md5List:function()
	{
	
	},
	checkBoxAll:function(a)
	{
		var b = oCBVar[a] || 0;
		$("td."+a).each(function(i){
			if(!b)
			{
				$(this).find("input").attr('checked','checked');
			}else
			{
				$(this).find("input").removeAttr("checked");
			}
		});
		oCBVar[a] = b?0:1;
	},
	tdCheck:function(o)
	{
		var a = $(o).find("input");
		var name = a.attr('name');
		if(a.attr('checked'))
		{
			a.removeAttr("checked");
		}else
		{
			a.attr('checked','checked');
		}
		//審核自動化
		if(name =='cbd' ||  name =='cbc')
		{
			this.checkbox_interaction(a,0,'cbk');
		}
		//發短信自動化
		if(name =='cbd' ||  name =='cbc' ||  name == 'cbk' ||  name  =='cbg')
		{
			this.checkbox_interaction(a,1,'cbm');
		}
	},
	cbd_jf:function(o,id)
	{
		$.o.e('cbd_why_'+id).style.display = o.checked ? '':'none';
		//刪除自動化
		o = $(o);
		this.checkbox_interaction(o,1,'cbd');
		this.checkbox_interaction(o,1,'cbm');
		this.checkbox_interaction(o,0,'cbk');
		this.checkbox_interaction(o,1,'cbd_md');
	},
	checkbox_interaction:function(src,yn,dst)
	{//
		var cbk = src.parents('tr').find("td."+dst+" input");
		if(src.attr('checked'))
		{
			cbk.attr('checked_old',cbk.attr('checked'));
			if(yn)
			{
				cbk.attr('checked','checked');
			}else
			{				
				cbk.removeAttr("checked");
			}
		}else
		{
			if(cbk.attr('checked_old'))
			{
				cbk.attr('checked','checked');
			}else if(yn)
			{
				cbk.removeAttr("checked");
			}
			cbk.removeAttr("checked_old");
		}
	},
	checkboxCheck:function(o)
	{
		o.checked=o.checked?false:true;
	},
	getRadio_:function(name)
	{
		var rs;
		$("input[@name="+name+"]").each(function(){
			if($(this).attr('checked'))rs=$(this).attr('value');
		});
		return rs;
	},
	getRadio:function(k)
	{
		var rs;
		var ipt = document['all'][k];
		for(var i=0;i<ipt['length'];i++)
		{
			a  = ipt[i];
			if(a['checked'])rs=a['value'];
		}
		return rs;
	},
	submit_:function()
	{
		var o = {cbd:{},cbc:{},cbk:{},cbp:{},cbg:{},cbd_jf:{},cbd_md:{}},t={},f=_.e('main_form');
		for(k in o)
		{
			$("input[@name="+k+"]").each(function(){
				var a = $(this);
				var id=a.attr("id");
				o[k][id] = {c:(a.attr('checked')?1:0),v:a.attr('value')};
				t[id] =oFrom.getRadio('cbd_why_'+id);
			});
		}
		o['cbd_why'] = t;
		//f.data.value = $.toJSON(o);
		alert(f.data.value);
		//f.submit();
	},
	submit:function()
	{
		var o = {cbd:{},cbc:{},cbk:{},cbp:{},cbg:{},cbd_jf:{},cbd_md:{}},t={},a,id,f=_.e('main_form');
		for(k in o)
		{
			var ipt = document['all'][k];
			if(ipt['length'])
			{
				for(var i=0;i<ipt['length'];i++)
				{
					a  = ipt[i];
					id = a['id'];
					o[k][id] = {c:(a['checked']?1:0),v:a['value']};
					t[id] =oFrom.getRadio('cbd_why_'+id);
				}
			}else
			{
				a  = ipt;
				id = a['id'];
				o[k][id] = {c:(a['checked']?1:0),v:a['value']};
				t[id] =oFrom.getRadio('cbd_why_'+id);
			}
		}
		o['cbd_why'] = t;
		f.data.value = $.toJSON(o);
		//alert(f.data.value);
		f.submit();
	}
};
/*****/
checkboxAll=function(a,b){b = b ? b['checked'] : true;a['checked'] = b;	for(var i=0;i<a.length;i++)a[i]['checked'] = b;};
checkboxChkFrom = function(a,note)	{note  = note || "提示:\n\t刪除將無法恢復!您確定要刪除所選嗎？\t\n";var b = false;	if(a['checked'])b = true;for(var i=0;i<a.length;i++){	if(a[i]['checked']){ b = true;	break;	}};if(b) if(confirm(note)) return true;return false;};
$(function(){
	$("tr._data_").mouseout(function(){							
		$(this).attr('class',this.onclick_class || this.oold_class || this.old_class || 'firstalt');
	}).mouseover(function(){
		var a = $(this);
		this.old_class = a.attr('class');
		a.attr('class','onChk_class');
	}).click(function(){
		if(this.c)
		{	
			this.c = 0;
			this.onclick_class = 0;
			$(this).attr('class',this.oold_class || 'firstalt');
		}else
		{	
			var a = $(this);
			this.c = 1;
			this.oold_class = this.old_class;
			this.onclick_class = 'onclick_class'; 
			a.attr('class','onclick_class');
		}
	}).each(function(i){
		if(i%2)
		{
			$(this).attr('class','firstalt');
		}else
		{
			$(this).attr('class','secondalt');
		}
	});
});